﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XuLyDuLieu
{
    
    public partial class frmCauHinhBoLoc : Form
    {
        public class ObjectShowCombobox
        {
            public Core.DataProcessing.KieuChia KieuChiaGio { get; set; }
            public string Name { get; set; }
            public ObjectShowCombobox()
            {
                this.KieuChiaGio = Core.DataProcessing.KieuChia.NULL;
                this.Name = "False";
            }
        }
        #region "[Khởi tạo]"
        public frmCauHinhBoLoc()
        {
            InitializeComponent();
        }
        #endregion

        #region "[Không cho  gười dùng nhập chữ]"
        private void txtSoLuongGio_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsNumber(e.KeyChar))
            {
                e.Handled = true;
            }
        }
        #endregion

        #region "[xử lý sự kiện checkbox]"
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                txtViTriThuocTinhCanChia.Enabled = false;
            }
            else
            { txtViTriThuocTinhCanChia.Enabled = true; }
        }
        #endregion

        #region "[Nút OK]"
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (!checkBox1.Checked)
                {
                    if (txtViTriThuocTinhCanChia.Text.Trim().CompareTo("0") == 0)
                    {
                        MessageBox.Show("Chưa chọn vị trí thuộc tính cần chia giỏ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                if (txtSoLuongGio.Text.Trim().CompareTo("0") == 0)
                {
                    MessageBox.Show("Chưa chọn số lượng giỏ cần chia", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return;
                }
                frmMain.SoLuongGio = int.Parse(txtSoLuongGio.Text.Trim());
                frmMain.m_maCotCanChia = int.Parse(txtViTriThuocTinhCanChia.Text.Trim());
                frmMain.KieuChia = (Core.DataProcessing.KieuChia)cmbKieuChiaGio.SelectedValue;
                this.Close();
            }
            catch { }
        }
        #endregion

        #region "[đóng lại]"
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region "[show litile attribites in method load]"
        private void frmCauHinhBoLoc_Load(object sender, EventArgs e)
        {
            try
            {
                txtSoLuongGio.Text = frmMain.SoLuongGio.ToString();
                txtViTriThuocTinhCanChia.Text = frmMain.m_maCotCanChia.ToString();

                ShowItemInCombobox();
            }
            catch { }
        }
        #endregion

        #region "[hiển thị thông tin trên combobox]"
        /// <summary>
        /// hiển thị thông tin trên combobox
        /// </summary>
        private void ShowItemInCombobox()
        {
            try {
                List<ObjectShowCombobox> listShowItem = new List<ObjectShowCombobox>();


                ObjectShowCombobox objItem1 = new ObjectShowCombobox();
                objItem1.Name = "Chia Giỏ Theo Chiều Rộng";
                objItem1.KieuChiaGio = Core.DataProcessing.KieuChia.TheoChieuRong;

                ObjectShowCombobox objItem2 = new ObjectShowCombobox();
                objItem2.Name = "Chia Giỏ Theo Chiều Sâu";
                objItem2.KieuChiaGio = Core.DataProcessing.KieuChia.TheoChieuSau;

                listShowItem.Add(objItem1);
                listShowItem.Add(objItem2);

                cmbKieuChiaGio.DataSource = listShowItem;
                cmbKieuChiaGio.DisplayMember = "Name";
                cmbKieuChiaGio.ValueMember = "KieuChiaGio";
            }
            catch { }
        }
        #endregion
    }
}
